package com.java1234.jxc.core;

import com.java1234.jxc.beans.SysUser;
import org.nutz.dao.Dao;
import org.nutz.dao.impl.FileSqlManager;
import org.nutz.dao.sql.Sql;
import org.nutz.dao.util.Daos;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;

@Component
@Order(1)
public class SetUp implements ApplicationRunner {

    @Autowired
    Dao dao;

    @Override
    public void run(ApplicationArguments args) throws Exception {

        System.out.println("------------------>"+"项目启动,now="+new Date());
        Daos.createTablesInPackage(dao, "com.java1234.jxc", false);
        Daos.migration(dao, "com.java1234.jxc", true, false, false);



        initSys(dao);

    }

   private void initSys(Dao dao) {
        if (0 == dao.count(SysUser.class)) {

            FileSqlManager fmq = new FileSqlManager("sqls");
            List<Sql> sqlListq = fmq.createCombo(fmq.keys());
            sqlListq.stream().forEach(sql->dao.execute(sql));



        }


    }
}
